import Vue from 'vue';
import App from './App';
import router from './router/indexPC.js';

import { version } from '@/../package.json';
let wsn = window.server_name || 'dev';
Vue.prototype.$version = `${version}-${wsn}`;

import qs from 'qs';
Vue.prototype.$qs = qs;
if (process.env.NODE_ENV === 'development') {
  console.log(
    '%c 项目中可用 qs（$qs.parse()/$qs.stringify()',
    'background:pink;'
  );
} //仅开发提示

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './theme/index.css';
Vue.use(ElementUI);

import store from './Store';
import 'font-awesome/css/font-awesome.min.css';

import { axios, api } from './Axios';
Vue.prototype.$axios = axios;
Vue.prototype.$api = api;
import VueAxios from 'vue-axios';
Vue.use(VueAxios, axios);

import _ from 'lodash';
Vue.prototype._ = _;
if (process.env.NODE_ENV === 'development') {
  console.log('%c 项目中可用 lodash（_）', 'background:pink;');
} //仅开发提示

// 通过script引入 dist/server_config.js 作为配置文件
// 开发时 window.server_config 只能返回 undefined
// 打包上线后 window.server_config 就可以返回配置对象
// 然后通过下面 mergeConfig 方法将两者合并返回可用的配置对象并存入原型链就可以全局使用了
import { mergeConfig } from './mergeConfig.js';
let serverConfig = null;

if (_.has(window, 'server_config')) {
  serverConfig = window.server_config.getServerConfig();
}
let $config = mergeConfig(serverConfig);

Vue.prototype.$config = $config;

import MD5 from 'md5';
Vue.prototype.MD5 = MD5;
Vue.filter('MD5', function(value) {
  return MD5(value);
});
if (process.env.NODE_ENV === 'development') {
  console.log('%c 项目中MD5已全局配置filter', 'background:pink;');
} //仅开发提示

import Toasted from 'vue-toasted';
Vue.use(Toasted, {
  fitToScreen: true,
  position: 'top-center',
  theme: 'outline',
  type: 'error',
  action: {
    text: 'X',
    onClick: (e, toastObject) => {
      toastObject.goAway(0);
    },
  },
});

import Moment from 'moment';
import 'moment/locale/zh-cn';
Vue.prototype.$moment = Moment;
if (process.env.NODE_ENV === 'development') {
  console.log('%c 项目中可用 moment（$moment', 'background:pink;');
} //仅开发提示

import '@/assets/reset.css';

Vue.config.productionTip = false;
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>',
});
